<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
	TopicDao topicDao = new TopicDaoImpl();//得到主题Dao的实例
	ReplyDao replyDao = new ReplyDaoImpl();//得到回复Dao的实例
	UserDao userDao = new UserDaoImpl();//得到用户Dao的实例
	BoardDao boardDao = new BoardDaoImpl();//得到板块Dao的实例
	
	int boardId = Integer.parseInt(request.getParameter("boardId"));//取得板块ID
	int p = Integer.parseInt(request.getParameter("page"));//取得页数
	List listTopic = topicDao.findListTopic(p, boardId);
	Board board = boardDao.findBoard(boardId);
	
	int prep = p;
	int nextp = p;
	if(listTopic.size()==20){
		nextp= p+1;
	}
	if(p>1){
		prep=p-1;
	}
	
	/* int boardId = 9;//暂时固定为JSP技术板块的ID
	int p=1;//页数暂固定为1
	List listTopic = topicDao.findListTopic(p,boardId);//取得该板块主题列表 */
	
	
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>帖子列表</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<style type="text/css">
        	*{
                padding: 0;
                margin: 0;
            }
            #apDiv1{
                width:99.5%;
                height:50px;
            }
            #apDiv2{
                width:99.5%;
                height:30px;
                background-color:#e0f0f9;
                text-align:left;
            }
            #apDiv3{
                width:99.5%;
                height:40px;
                font-size: 19px;
                line-height: 40px;
                margin-top: 15px;
                margin-bottom: 15px;
                background-color: #FFA500;
                text-align:center;
            }
            #apDiv4{
                width:99.5%;
                height:25px;
                margin-bottom: 15px;
                text-align:center;
            }	
            /*#apDiv5{
                width:99.5%;
                height:25px;
                text-align:center;
            }*/
            #apDiv7{
                width:99.5%;
                height:25px;
                margin-top: 15px;
                text-align:center;
            }
            /*.style1{
                color:#3399cc;
                font-size:36px;
            }*/
            .style1{
            	font-family: "黑体";
            	font-weight: bold;
            	font-size: 40px;
            	color: #3399cc;
            }
            .style2{
            	color: black;
            	font-size: 20px;
            }
            .board td{
            	text-align: center;
            	font-size: 17px;
            }
			tr:nth-child(odd){
				background-color: #D3D3D3;
			}
			tr:nth-child(even){
				background-color: #FFFFFF;
			}
			tr:hover{
				background-color: #FFFF66;
			}
        </style>
  </head>
  <body>
	     <center>
        	<div id="apDiv1">
            <div align="center" class="style1">校园BBS系统</div>
        	</div>
        	<div class="style2" id="apDiv2">
            	&nbsp;您尚未&nbsp;&nbsp;<a href="login.jsp" target="_blank">登录</a>&nbsp;&nbsp;|
            	&nbsp;&nbsp;<a href="reg.jsp" target="_blank">注册</a>
        	</div>
			<div id="apDiv3">
				<a>您所在的位置>></a>&nbsp;<a href="index.jsp">论坛首页</a>&nbsp;<a>>></a>&nbsp;
				<a href="list.jsp?page=1&boardId=<%=boardId %>"><%=board.getBoardName() %></a>&nbsp;
			</div>
			<div id="apDiv4">
				<a href="post.jsp?boardId=${param.boardId}<%-- <%=boardId %> --%>"><img src="image/post.gif"/></a>
			</div>
<!-- 		<div id="apDiv5">
				<a href="#">上一页</a>&nbsp;<a href="#">下一页</a>&nbsp;
			</div> -->
			<div id="apDiv6">
			    <table class="board" width="99.5%" border="1" cellpadding="0" cellspacing="0">
				    <tr>
					  <td colspan="4">&nbsp;</td> 
					</tr>
					<tr>
					  <td></td>
					  <td style="color:#00C758;font-size: 22px;">文章</td> 
					  <td style="color:#00C758;font-size: 22px;">作者</td> 
					  <td style="color:#00C758;font-size: 22px;">回复</td>
					</tr>
					<!-- 列表主题 -->
					<%-- <c:forEach items="<%=listTopic %>" var="topic"> --%>
					<%
						for(int i=0;i<listTopic.size();i++){
						Topic topic = (Topic)listTopic.get(i);
						User user = userDao.findUser(topic.getUserId());
					 %>
					<tr>
					  <td width = "5%">
					  	<img src="image/topic.gif" width="30" height="30"/>
					  </td>
					  <td>
					  	<a href="detail.jsp?page=1&boardId=<%=boardId %>&topicId=<%=topic.getTopicId() %>"><%=topic.getTitle() %></a>
					  </td> 
					  <td width="15%"><%=user.getUserName() %></td>
					  <td width="15%"><%=replyDao.findCountReply(topic.getTopicId()) %></td>
					</tr>
					<%
						} 
					%>
					<%-- </c:forEach> --%>
				</table>
			</div>
			<div id="apDiv7">
				<a href="list.jsp?page=<%=prep %>&boardId=<%=boardId %>">上一页</a>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="list.jsp?page=<%=nextp %>&boardId=<%=boardId %>">下一页</a>
			</div>
		 </center>
	</body>
</html>
